/**
 * @Project TMHSC
 * @Author Tran Manh Hung
 * @Email: hungtmit@gmail.com | tmh@xwebgate.com
 * @Copyright © 2011 TMH. All rights reserved
 * @Createdate Jan 26, 2011
 * @Createtime 12:22:10 PM
 */

package com.tmh.Flint
{
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Rectangle;

	import org.flintparticles.common.events.ParticleEvent;
	import org.flintparticles.common.particles.Particle;
	import org.flintparticles.twoD.emitters.Emitter2D;
	import org.flintparticles.twoD.renderers.PixelRenderer;

	public class Main extends Sprite
	{
		private var gravityWells:Emitter2D;

		private var gravityWells2:Emitter2D;

		private var gravityWells3:Emitter2D;

		private var logoFirework:Emitter2D;

		private var startEmitter:Emitter2D;

		private var tweenToGHHG:Emitter2D;

		private var tweenToHGGH:Emitter2D;

		private var renderer:PixelRenderer;

		public function Main()
		{
			var offsetX:Number = 240;
			var offsetY:Number = 250;

			gravityWells = new GravityWells();
			gravityWells2 = new GravityWells();
			gravityWells3 = new GravityWells();
			startEmitter = new TweenLogoFirstEmitter(offsetX, offsetY);
			tweenToGHHG = new TweenLogoToGHHG(offsetX, offsetY);
			tweenToHGGH = new TweenLogoToHGGH(offsetX, offsetY);

			renderer = new PixelRenderer(new Rectangle(0, 0, 800, 500));
			renderer.addFilter(new BlurFilter(2, 2, 1));
			renderer.addFilter(new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,.99,0]));

			renderer.addEmitter(gravityWells);
			renderer.addEmitter(gravityWells2);
			renderer.addEmitter(gravityWells3);
			renderer.addEmitter(startEmitter);
			renderer.addEmitter(tweenToGHHG);
			renderer.addEmitter(tweenToHGGH);
			addChild(renderer);

			startEmitter.addEventListener(ParticleEvent.PARTICLE_DEAD, moveToTweenGHHG);
			tweenToGHHG.addEventListener(ParticleEvent.PARTICLE_DEAD, moveToTweenHGGH);
			tweenToHGGH.addEventListener(ParticleEvent.PARTICLE_DEAD, moveToTweenGHHG);

			startEmitter.start();
			tweenToGHHG.start();
			tweenToHGGH.start();

			gravityWells.start();
			gravityWells2.start();
			gravityWells3.start();
		}

		private function moveToTweenGHHG(event:ParticleEvent):void
		{
			event.particle.revive();
			tweenToGHHG.addParticles(Vector.<Particle>([event.particle]), true);
		}

		private function moveToTweenHGGH(event:ParticleEvent):void
		{
			event.particle.revive();
			tweenToHGGH.addParticles(Vector.<Particle>([event.particle]), true);
		}
	}
}